var EventList = function () {

    var initPickers = function () {
        //init date pickers
        $('.date-picker').datepicker({
            rtl: Metronic.isRTL(),
            autoclose: true
        });
    }
    var refillgrid = function (obj){ // 重新填充数据  
    	
    }
    var handleOrders = function() {

        var grid = new Datatable();
            grid.init({
                src: $("#datatable_orders"),
                onSuccess: function(grid) {
                   console.log(grid);
                },
                onError: function(grid) {
                    // execute some code on network or other general error  
                },
                
                dataTable: {  // here you can define a typical datatable settings from http://datatables.net/usage/options 
                    "aLengthMenu": [
                        [20, 50, 100, 150, -1],
                        [20, 50, 100, 150, "All"] // change per page values here
                    ],
                    "aoColumns": [   {"mDataProp":"id","sClass": "center" },
                                     {"mDataProp":"title","sClass": "center" },
                                     {"mDataProp":"userNickname","sClass": "center" },
                                     {"mDataProp":"status","sClass": "center"}
                                     ],
                                     
                     "aoColumnDefs": [
//                                      { "aTargets": [7], 
//                                    	   "bSearchable": false, 
//                                    	   "sType": 'date',
//                                    	   "fnRender": function ( oObj ) {
//                                    		  
//                                    		   var mDate = moment(oObj.aData.createTime);
//                                    	 
//                                    	              return  mDate.format("YYYY-MM-DD HH:mm");
//                                    	   }
//                                     },
								  	{ "aTargets": [0], 
                                	   "bVisible": false
                                     },
                                     
                                 
                                     {
                                     "aTargets": [3],
                                     "mData": "操作",
                                     "mRender": function (data, type, full) {
                                    	 console.log(full);
                                    	 
                                    	 var btn = "<div class='margin-bottom-5'><a class='btn btn-default btn-sm' href='admin/event/push/"+full.id+".htm'><i class='fa fa-pencil'>推送</i></a>";
											btn+="</div>";
//                                    	 return '<div><a class="btn  blue" href="admin/event/toedit/'+full.id+'.htm"> 编辑</a></div><div><a class="btn  blue" href="admin/event/toedit/'+full.id+'.htm">详情</a></div>';
                                        // return '<a href="javascript:void(0);" class="delete" tag=' + data + '>删除</a>';
                                    	return  btn;
                                    	 
                                    	 
                                       }
                                     },
                      ],
                    "iDisplayLength": 20, // default record count per page
                    "iDisplayStart":0,
                    "bPaginate":true,
                    "bServerSide": true, // server side processing
                    "sAjaxSource" : "admin/event/list.json?now=" + new Date().getTime(),
                    "fnServerData" : function(sSource, aDataSet, fnCallback) {  
                        $.ajax({  
                            "dataType" : 'json',  
                            "type" : "POST",  
                            "url" : "admin/event/list.json",  
                            "data" : {
                        	"startTime":$('#order_date_from').val(),
                            "status":$('#e_Status').val(),
                            "endTime":$('#order_date_to').val()
                            },  
                            "success" : fnCallback  
                        });  
                    },  
                    "aaSorting": [[ 1, "asc" ]] // set first column as a default sort by asc
                }
            });
        	$('.btn btn-sm yellow filter-submit margin-bottom').click(function () {
        	
            	grid.fnDraw();
        	});
            // handle group actionsubmit button click
            grid.getTableWrapper().on('click', '.table-group-action-submit', function(e){
                e.preventDefault();
                var action = $(".table-group-action-input", grid.getTableWrapper());
                if (action.val() != "" && grid.getSelectedRowsCount() > 0) {
                    grid.addAjaxParam("sAction", "group_action");
                    grid.addAjaxParam("sGroupActionName", action.val());
                    var records = grid.getSelectedRows();
                    for (var i in records) {
                        grid.addAjaxParam(records[i]["name"], records[i]["value"]);    
                    }
                    grid.getDataTable().fnDraw();
                    grid.clearAjaxParams();
                } else if (action.val() == "") {
                    Metronic.alert({type: 'danger', icon: 'warning', message: 'Please select an action', container: grid.getTableWrapper(), place: 'prepend'});
                } else if (grid.getSelectedRowsCount() === 0) {
                    Metronic.alert({type: 'danger', icon: 'warning', message: 'No record selected', container: grid.getTableWrapper(), place: 'prepend'});
                }
            });

    }

    return {

        //main function to initiate the module
        init: function () {
            initPickers();
            handleOrders();
        }
    	

    };

}();

var test ={};





